/* NinjaTrader Strategy of Strategy 1.38 Generated by StrategyQuant version 3.6.3 Generated at Sat Sep 06 21:09:00 GMT 2014 Tested on EURUSD_fhdb, D1, 01.11.2007 - 29.03.2013 Spread: 2.5, Slippage: 0.0, Min distance of stop from price: 5.0 */ #region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion namespace NinjaTrader.Strategy { /// /// Enter the description of your strategy here /// [Description("Enter the description of your strategy here")] public class Strategy138 : SQManagedStrategy { #region Variables // Wizard generated variables // User defined variables (add any user defined variables below) #endregion /// /// This method is used to configure the strategy and is called once before any strategy method is called. /// protected override void Initialize() { base.Initialize(); ReplacePendingOrders = true; ExitOnClose = false; MinimumPTSL = 30; MaximumPTSL = 300; PendingOrderValidOneBar = false; BarsRequired = 120; StrictStopPrices = true; LimitSignalsToRange = false; TimeRangeFrom = 0800; TimeRangeTo = 1600; MaxTradesPerDay = 0; // 0 means unlimited } /// /// Called on each bar update event (incoming tick) /// protected override void OnBarUpdate() { // ------------------------------------------ // STRATEGY MANAGEMENT // ------------------------------------------ if(Bars.FirstBarOfSession) tradesPerDay = 0; // Stop/Limit order expiration handling // Long -------- if(pendingEntryOrder != null && pendingEntryOrder.OrderAction == OrderAction.Buy) { // Expiration if(sqGetPendingOrderBars(pendingEntryOrder) >= 5) { CancelOrder(pendingEntryOrder); } } // Short -------- if(pendingEntryOrder != null && pendingEntryOrder.OrderAction == OrderAction.SellShort) { // Expiration if(sqGetPendingOrderBars(pendingEntryOrder) >= 5) { CancelOrder(pendingEntryOrder); } } // ------------------------------------------ // ENTRY RULES // ------------------------------------------ tradeEntered = false; if(sqCheckTimeWithinRange()) { // Long -------- if(maxTradesPerDay == 0 || tradesPerDay < maxTradesPerDay) { bool LongEntryCondition = ((CCI(20)[0] > 0 || CCI(40)[0] > 0) || ((SQBBandWidthRatio(98, 2.0)[2-1] < sqTrueRange(83+2-1)) && (SQBBandWidthRatio(98, 2.0)[0] >= sqTrueRange(83)))); if(LongEntryCondition == true) { double price = roundPrice(HeikenAshi().HAClose[2+0] + (0.1) * (Math.Abs(sqKeltnerDown(32, 4.2, 0) - Ichimoku(Median, 9, 26, 52).TenkanSen[0]))); sqEnterLongStop(price); } } // Short -------- if(maxTradesPerDay == 0 || tradesPerDay < maxTradesPerDay) { bool ShortEntryCondition = ((CCI(20)[0] < 0 || CCI(40)[0] < 0) || ((SQBBandWidthRatio(98, 2.0)[2-1] > sqTrueRange(83+2-1)) && (SQBBandWidthRatio(98, 2.0)[0] <= sqTrueRange(83)))); if(ShortEntryCondition == true) { double price = roundPrice(HeikenAshi().HAClose[2+0] + (-0.1) * (Math.Abs(sqKeltnerUp(32, 4.2, 0) - Ichimoku(Median, 9, 26, 52).TenkanSen[0]))); sqEnterShortStop(price); } } } // ------------------------------------------ // MANAGE TRADE & EXIT RULES // ------------------------------------------ if(tradeEntered) { // don't modify SL is new order was just placed return; } IOrder slOrder = sqGetStopLossOrder(); double priceLevel; // Long -------- // Exit After X Bars if(Position.MarketPosition == MarketPosition.Long) { if (BarsSinceEntry("Long") >= 7-1) { sqExitLong("LongExitAfterXBars"); } } // Short -------- if(Position.MarketPosition == MarketPosition.Short) { // Exit After X Bars if (BarsSinceEntry("Short") >= 7-1) { sqExitShort("ShortExitAfterXBars"); } } } override protected void sqDefineStopLoss(int direction) { stopLoss.type = CalculationMode.Ticks; if(direction == 1) { // long stopLoss.value = 33; } else { // short stopLoss.value = 33; } } override protected void sqDefineProfitTarget(int direction) { profitTarget.type = CalculationMode.Ticks; if(direction == 1) { // long profitTarget.value = 0; } else { // short profitTarget.value = 0; } } #region Properties #endregion } }